<?php
/**
 * Creater: 李青林
 * Date Time : 2018/10/25 18:12
 */

namespace App\Admin\Controllers;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use App\Http\Models\StatisticsGoodsInfo;

class StatisticsController extends Controller
{
    use ModelForm;
    protected $headerStr = '日志';

    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header($this->headerStr . '管理');
            $content->description('统计管理');
            $content->body($this->grid());
        });

    }


    protected function grid()
    {
        return Admin::grid(StatisticsGoodsInfo::class, function (Grid $grid) {
            $grid->model()->where('date', date('Ymd'));
            $grid->id('编号')->sortable();
            $grid->type('类型')->display(function ($value) {
                $info = [
                    1 => '爆款单',
                    2 => '秒杀单',
                    3 => '纠错统计',
                ];
                return $value == 0 ? '平推单' : ($value < 4 ? $info[$value] : '');
            });
            $grid->online('在线商品')->display(function ($value) {
                return $this->type == 3 ? '----' : $value;
            });
            $grid->all_unaudited('全部待审核');
            $grid->today_unaudited('今日待审核');
            $grid->today_adopt('今日通过');
            $grid->today_refuse('今日拒绝')->display(function ($value) {
                return $this->type == 3 ? '----' : $value;
            });
            $grid->filter(function ($filter){
                $filter->disableIdFilter();
            });
            $grid->disableExport();
            $grid->disableRowSelector();
            $grid->perPages([10, 20, 30, 40, 50]);
            $grid->disableActions();
            $grid->paginate(env('Admin_Limit'));
            $grid->disableCreateButton();
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {
            $content->header($this->headerStr . '管理');
            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {
            $content->header($this->headerStr . '管理');
            $content->body($this->form());
        });
    }

    public function show($id)
    {
        return Admin::content(function (Content $content) use ($id) {
            $content->header($this->headerStr . '管理');
            $content->body($this->form()->edit($id));
        });
    }
}